<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="用户id">
                <el-input
                    v-model="queryParams.userid"
                    placeholder="请输入用户id"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="昵称">
                <el-input
                    v-model="queryParams.nickName"
                    placeholder="请输入昵称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="手机号">
                <el-input
                    v-model="queryParams.phone"
                    placeholder="请输入手机号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="充值订单号">
                <el-input
                    v-model="queryParams.orderCode"
                    placeholder="请输入充值订单号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
           <!-- <el-form-item label="充值金额">
                <el-input
                    v-model="queryParams.price"
                    placeholder="请输入充值金额"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item> -->
            <el-form-item label="支付状态">
                <el-select style="width: 200px;" v-model="queryParams.payStatus"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in dict.type.pay_status_options"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>

						<el-form-item label="创建时间">
						  <el-date-picker
						    v-model="dateRange"
						    type="datetimerange"
						    range-separator="-"
						    start-placeholder="开始日期"
						    value-format="yyyy-MM-dd HH:mm:ss"
						    style="width:333px;"
						    :default-time="['00:00:00','23:59:59']"
						    end-placeholder="结束日期">
						  </el-date-picker>
						</el-form-item>

            <el-form-item >
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="总金额" align="center" prop="totalPrice" :show-overflow-tooltip="true"/>
            <el-table-column label="实际支付金额" align="center" prop="payPrice" :show-overflow-tooltip="true"/>
            <el-table-column label="赠送金额" align="center" prop="bonusPrice" />
           <!-- <el-table-column label="充值金额" align="center" prop="rechargeAmount" :formatter="(row) => {return '￥' + (row.rechargeAmount || 0)}"/>
            <el-table-column label="可退款" align="center" prop="refundablePrice" :formatter="(row) => {return '￥' + (row.refundablePrice || 0)}"/>
            <el-table-column label="已退款" align="center" prop="retreatedPrice" :formatter="(row) => {return '￥' + (row.retreatedPrice || 0)}"/> -->
            <!-- <el-table-column label="已消费" align="center" prop="consumptionAmount" :formatter="(row) => {return '￥' + ( row.consumptionAmount || 0)}"/> -->
            <el-table-column label="支付状态" align="center" prop="payStatus">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.pay_status_options" :value="row.payStatus" />
                </template>
            </el-table-column>
            <el-table-column label="支付类型" align="center" prop="payChannelCode">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.pay_channel_code" :value="row.payChannelCode" />
                </template>
            </el-table-column>
            <!-- <el-table-column label="昵称" align="center" prop="nickName" :show-overflow-tooltip="true"/>
            <el-table-column label="头像地址" align="center">
                <template slot-scope="{row}">
                    <el-image
                      v-if="row.avatar"
                      style="width: 40px; height: 40px"
                      :src="row.avatar"
                      :preview-src-list="[row.avatar]">
                    </el-image>
                </template>
            </el-table-column> -->
            <el-table-column label="支付时间" align="center" prop="payTime" width="180" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

    </div>
</template>

<script >
import * as api from "@/api/finance/recharge";

export default {
  name: 'Recharge',
  dicts: ['pay_status_options','pay_type_options','pay_channel_code'],
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list:[],//页面数据
      defaultTime1: [
        new Date(2000, 1, 1, 0, 0, 0),
        new Date(2000, 2, 1, 23, 59, 59),
      ],
      dateRange:[],
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      if(!this.dateRange) this.dateRange = []
      if(this.dateRange.length) {
        queryParams.startTime = this.dateRange[0]
        queryParams.endTime = this.dateRange[1]
      }
      api.listRecharge(queryParams).then(response => {
        let rows = response.rows || [];
        this.list = rows.map(item=>{
          return {
            ...item,
            totalPrice:item.totalPrice / 100,
            payPrice:item.payPrice / 100,
            bonusPrice:item.bonusPrice / 100,
          }
        })
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(api.EXPORT_URL, {
          ...this.queryParams
      }, `recharge_${new Date().getTime()}.xlsx`);
    }
  }
}
</script>
